#pragma once

enum 
{
	COORDI_X = 0,
	COORDI_Y,
	COORDI_Z,
	COORDI_COUNT
};

class CGsensorInfo
{
public:
	CGsensorInfo(int x, int y, int z, int nDir)
	{
		m_nCoordinate[COORDI_X] = x;
		m_nCoordinate[COORDI_Y] = y;
		m_nCoordinate[COORDI_Z] = z;
		m_nDir = nDir;
	};
	~CGsensorInfo(){};

	int GetX() { return m_nCoordinate[COORDI_X]; };
	int GetY() { return m_nCoordinate[COORDI_Y]; };
	int GetZ() { return m_nCoordinate[COORDI_Z]; };
	int Get(int nCoordinate)
	{
		return m_nCoordinate[nCoordinate];
	};
	int GetScaled(int nCoordinate, FLOAT fScale)
	{
		return (int)(fScale*m_nCoordinate[nCoordinate]);
	}
	int GetDir() { return m_nDir; };

	void SetGSensorData(int x, int y, int z, int nDir)
	{
		m_nCoordinate[COORDI_X] = x;
		m_nCoordinate[COORDI_Y] = y;
		m_nCoordinate[COORDI_Z] = z;
		m_nDir = nDir;
	};

private:
	int m_nCoordinate[COORDI_COUNT];
	int m_nDir;
};


// CWndGSensorGraph

class CWndGSensorGraph : public CWnd
{
	DECLARE_DYNAMIC(CWndGSensorGraph)

private:
	CPen			m_penX, m_penXbk;
	CPen			m_penY, m_penYbk;
	CPen			m_penZ, m_penZbk;
	CPen			m_penBar;
	CPen			*m_pPen[2][COORDI_COUNT];

	CBitmap			m_bmpGraph;

	CArray <CGsensorInfo *, CGsensorInfo *> m_arrGsensorInfo;
	CCriticalSection m_csGSen;
	int m_nDirection;
	int m_Y_middle, m_Y_2g;

	DWORD m_dwColorText;

	int m_nGraphType;
	BOOL m_bAvailable;

public:
	CWndGSensorGraph();
	virtual ~CWndGSensorGraph();

	void SetGSensorVal(int nX, int nY, int nZ, int nDir = 0, BOOL bAvaiableFileBased = FALSE);
//	void UpdateWnd();
	void UpdateWnd(BOOL bAvailbleFileBased = FALSE);
	void ClearGSensor();

	void DrawGraphTimeBased();
	void DrawGraphFileBased();

	int GetGSensorGraphType() { return m_nGraphType; };
	void SetGSensorGraphType(int nGraphType) { m_nGraphType = nGraphType; };


	//////////////////////////////////////////////////////////////////////////
	//GraphType : file-based

	BOOL IsLoaded() { return m_pDataAll != NULL; };
	void SetTotalGSensorData(BYTE *pDataAll, DWORD dwDataSize, DWORD dwDataCount);
	void SetPos(int nPos);

	void DrawTotalGSensorData();
	
	CRect m_rtCurRect;
	BYTE *m_pDataAll;
	DWORD m_dwDataSize;
	DWORD m_dwDataCount;

	int m_nPos;
	CDC m_memDCGraph;
	CBitmap m_bitmapGraph, *m_pOldbitmapGraph;

protected:
	afx_msg void OnPaint();
	DECLARE_MESSAGE_MAP()
public:
	afx_msg int OnCreate(LPCREATESTRUCT lpCreateStruct);
};

